package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MenuDao1;
import com.itheima.pojo.Menu;
import com.itheima.pojo.Permission;
import com.itheima.service.MenuService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Tony
 * @create 2021-12-07 19:59
 */
@Service(interfaceClass = MenuService1.class)
@Transactional
public class MenuService1Impl1 implements MenuService1 {
    @Autowired
    private MenuDao1 menuDao;

    @Override
    public List<Menu> findAllMenu() {
        return menuDao.findAllMenu();
    }

    @Override
    public void addForRole(Integer roleId, Integer[] menuIds) {
        for (Integer menuId : menuIds) {
            if (menuId != null) {
                Integer exit = menuDao.isExit(menuId, roleId);
                if (exit == null) {
                    menuDao.setRoleAndMenu(roleId, menuId);
                }
            }
        }

    }

    @Override
    public Integer[] findMenuByRoleId(Integer roleId) {
        return menuDao.findMenuByRoleId(roleId);
    }

    @Override
    public void deleteRoleAndMenuById(Integer roleId) {
        menuDao.deleteRoleAndMenuById(roleId);
    }

    @Override
    public void deleteMenuById(Integer roleId) {
        menuDao.deleteMenuById(roleId);
    }

    @Override
    public void addMenuById(Integer menuId1, Integer roleId) {
        menuDao.addMenuById(menuId1, roleId);
    }

}
